/**
 * Apr 24, 2010
 */
package org.tomale.id.projects.ui;

import java.util.Calendar;

import org.eclipse.nebula.widgets.ganttchart.GanttChart;
import org.eclipse.nebula.widgets.ganttchart.GanttEvent;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.editor.FormPage;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.forms.widgets.TableWrapData;
import org.eclipse.ui.forms.widgets.TableWrapLayout;

/**
 * @author ferd
 *
 */
public class ProjectTimelinePage extends FormPage {

	public static final String PAGE_ID = "org.tomale.id.projects.ui.editor.project.timeline";
	public static final String PAGE_TITLE = "Timeline";
	
	GanttChart _chart;
	
	public ProjectTimelinePage(FormEditor editor){
		super(editor,PAGE_ID,PAGE_TITLE);
	}

	@Override
	protected void createFormContent(IManagedForm managedForm) {
		final ScrolledForm form = managedForm.getForm();
		FormToolkit tk = managedForm.getToolkit();
		Composite body = form.getBody();
		tk.paintBordersFor(body);
		form.setText(this.getTitle());
		
		TableWrapLayout layout = new TableWrapLayout();
		layout.numColumns = 1;
		body.setLayout(layout);

		createGanttSection(body, tk);
	}
	
	private void createGanttSection(Composite parent, FormToolkit toolkit){
		Section section = toolkit.createSection(parent,
				Section.DESCRIPTION | Section.TITLE_BAR | Section.EXPANDED);
		section.setText("Timeline");
		section.setDescription("This section displays the project timeline.");
		TableWrapData td = new TableWrapData(TableWrapData.FILL_GRAB,
				TableWrapData.FILL_GRAB);
		section.setLayoutData(td);
		
		Composite comp = toolkit.createComposite(section);
		toolkit.paintBordersFor(comp);
		GridLayout layout = new GridLayout();
		layout.numColumns = 1;
		comp.setLayout(layout);
		
		_chart = new GanttChart(comp, SWT.NONE);
		toolkit.adapt(_chart);
		_chart.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
		
		Calendar one = Calendar.getInstance();
		Calendar two = Calendar.getInstance();
		two.add(Calendar.DATE, 10);
		GanttEvent event = new GanttEvent(_chart, "test", one, two, 50);
		
		section.setClient(comp);
	}
}
